package com.common.sqlmanager;

import java.sql.Connection;
import java.sql.DriverManager;

public class SqlManager {
	        static SqlManager sqlManager;
	        static Connection connection;
	        
	
	        private SqlManager(){
	        	
	        }
	
            public static SqlManager shareManager(){
            	if(sqlManager == null){
            		sqlManager = new SqlManager();
            	}	
            	return sqlManager;
            }
            
            public Connection getConnection(String sql) throws Exception {
       		 /**

       		 * create table test( content varchar(50) )engine=innodb,charset=utf8mb4

       		 */
            if(connection == null){
       		 Class.forName("com.mysql.jdbc.Driver");
       		 connection = DriverManager.getConnection("jdbc:mysql://127.0.0.1:3306/WeiboAD?useUnicode=true&characterEncoding=utf8", "root", "root");
       		 connection.setAutoCommit(true);
       		 //通过查询运行设置字符集的命令
       		 connection.prepareStatement("set names utf8mb4").executeQuery();
       		 System.out.println("sql:"+sql);
            	}
       	     return connection;
       		 }
          
}
